package demo13;

class Adder extends Thread{
    @Override
    public void run() {
        synchronized (Adder.class) {
            for (long i = 0; i < 10_0000_0000L; i++) {
                ThreadDemo.n++;
            }
        }
    }
}

class Suber extends Thread{
    @Override
    public void run() {
        synchronized (Adder.class) {
            for (long i = 0; i < 10_0000_0000L; i++) {
                ThreadDemo.n--;
            }
        }
    }
}
public class ThreadDemo {
    public static int n = 0;

    public static void main(String[] args) throws InterruptedException {
        Thread a = new Adder();
        Thread b = new Suber();
        
        a.start();
        b.start();
        
        a.join();
        b.join();

        System.out.println(n);
    }
}
